package com.cc.flyingfish.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

import static com.cc.flyingfish.util.BusinessStatusConstant.*;

/**
 * @author CHENCHEN
 * @title  统一响应实体
 * @createTime 2023-02-27 21:33
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class CommonResponse<T> implements Serializable {

    private static final long serialVersionUID = 5199943609441909608L;

    /** 错误码 */
    private Integer code;

    /** 错误消息 */
    private String message;

    /** 响应数据 */
    private T Data;

    public CommonResponse(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    //成功——无返回数据
    public static CommonResponse SUCCESS = new CommonResponse(OK, OK_MESSAGE);

    //成功——有返回数据
    public static CommonResponse SUCCESS(String msg, Object data){
        return new CommonResponse<>(OK, msg, data);
    }

    //失败——无返回数据
    public static CommonResponse FAIL = new CommonResponse(ERR, ERR_MESSAGE);

    //败——有返回数据
    public static CommonResponse FAIL(String msg, Object data){
        return new CommonResponse(ERR, msg, data);
    }

    //业务异常
    public static CommonResponse BUSINESSEXCEPTION(Integer code, String message){
        return new CommonResponse(code, message);
    }

    //业务异常
    public static CommonResponse BUSINESSEXCEPTION(Integer code, String message, Object data){
        return new CommonResponse<>(code, message, data);
    }
}
